import urllib.request

url = 'https://www.douban.com/'
# url = "https://www.baidu.com"
# 请求头
headers = {
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36"
}
# 构建请求对象
request = urllib.request.Request(url,headers=headers)
# 发送请求对象  获取响应对象
response = urllib.request.urlopen(request)

data = response.read().decode('utf-8');
# data = str(response.read())
print(type(data))

# 保存到文件
with open('01cookie.html', 'w', encoding='utf-8') as f:
    f.write(data)